﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_PERMISSION.Base;
using ERP_RORZE_PRODUCT.Product.DAO;

namespace ERP_RORZE_PRODUCT.Product.XLBM
{
    public partial class ctrlMeMa : DevExpress.XtraEditors.XtraUserControl
    {
        ClsXLBM clsXLBM = new ClsXLBM();
        private LogUtils log;
        DataTable dt;
        public ctrlMeMa()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        void Reload(object sender, EventArgs e)
        {
            dt = clsXLBM.GetAllMeMa();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }
        private void ctrlMeMa_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            frm_MeMaAdd frmAdd = new frm_MeMaAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.Show();
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            frm_MeMaEdit frmEdit = new frm_MeMaEdit();
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.Some = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Some").ToString();
            frmEdit.Show();
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            clsXLBM.DeleteMeMa(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Some").ToString());

            //write Log
            log.Table = LogConstant.Table.Product.MeMa;
            log.Task = LogConstant.Task.Delete;
            log.Description = "Some: " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Some");
            log.WriteLog();

            Reload(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            btnAddNew_Click(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            btDelete_Click(sender, e);
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            btEdit_Click(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }
    }
}
